package com.aozhi.aipower.operation.entity.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

/**
 * @author lunzi
 */
@Getter
public enum ProductType implements IEnum<Integer> {
  // 新品
  NEW(1),
  // 爆款
  HOT(2),
  ;

  private final int code;

  ProductType(int code) {
    this.code = code;
  }

  @JsonValue
  @Override
  public Integer getValue() {
    return this.code;
  }

  /**
   * 根据 code 查找枚举
   * @param code code
   * @return code对应的枚举
   */
  @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
  public static ProductType findEnumByCode(Integer code){
    for (ProductType item : ProductType.values()) {
      if (item.getCode() == (code)) {
        return item;
      }
    }
    return null;
  }

}
